#!/usr/bin/env python
#coding=utf-8
'''
Created on Jul 22, 2010
@author: lxd
'''
import wx
from common.tools import Tools
from thread_login import LoginThread

class MainLoginDialog(wx.Dialog):
    def __init__(self):
        wx.Dialog.__init__(self, None, -1, u'主号登录', size=(300, 100))

        self.lblName = wx.StaticText(self, -1, u"用户名:")
        self.txtName = wx.TextCtrl(self, -1, "lxdcyh@163.com", size=(150, -1))
        self.lblPwd = wx.StaticText(self, -1, u"密码:")
        self.txtPwd = wx.TextCtrl(self, -1, "lixudong", size=(150, -1))
        self.txtName.SetFocus()    
        self.lblMessage = wx.StaticText(self, -1, '')         
        self.btnLogin = wx.Button(self, -1, u'登录')
        self.btnLogin.SetDefault()
        
        infoSizer = wx.BoxSizer(wx.HORIZONTAL)
        infoSizer.Add(self.lblName, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        infoSizer.Add(self.txtName, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        infoSizer.Add(self.lblPwd, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        infoSizer.Add(self.txtPwd, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
        infoSizer.Add(self.btnLogin, 0, wx.ALL, 5)
        
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(infoSizer, 0, wx.ALL, 5)
        mainSizer.Add(self.lblMessage, 0, wx.ALL, 5)
        
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        mainSizer.SetSizeHints(self)  
        
        self.Bind(wx.EVT_BUTTON, self.OnLoginClick, self.btnLogin) 
        
    def OnLoginClick(self, event):
        name = self.txtName.GetValue().strip()
        pwd = self.txtPwd.GetValue().strip()
        if name != '' and pwd != '':        
            loginThread = LoginThread(self, name, pwd)
            loginThread.setDaemon(True)  
            loginThread.start()  
        else:
            wx.MessageBox(u'不得为空', u'友情提示', style=wx.OK | wx.ICON_EXCLAMATION) 
        
    def messageCall(self, msg):
        self.lblMessage.SetLabel(msg)  
        
    def successCall(self, inviteUrl): 
        self.inviteUrl = inviteUrl       
        self.EndModal(wx.ID_OK)      
                         
if __name__ == "__main__":
    app = wx.App()
    MainLoginDialog().Show()
    app.MainLoop()
